#
# Compare two topologies.  Which splits exist in one tree, but not the other?
#

import sys
from dendropy import Tree

t1path = sys.argv[1]
t2path = sys.argv[2]

t1 = Tree()
t2 = Tree()
t1.read_from_path(t1path, "newick")
t2.read_from_path(t2path, "newick")

d1 = [nd for nd in t1.postorder_node_iter()]
d2 = [nd for nd in t2.postorder_node_iter()]

for i in range(0, d1.__len__() ):
    n1 = d1[i]
    if i < d2.__len__():
        n2 = d2[i]
    else:
        n2 = Node()
    
    if n1.is_leaf():
        continue
    else:
        n1_leafs = n1.leaf_nodes()
        n2_leafs = n2.leaf_nodes()
        n1_leaf_strs = []
        n2_leaf_strs = []
        for l in n1_leafs:
            n1_leaf_strs.append( l.get_node_str() )
        for l in n2_leafs:
            n2_leaf_strs.append( l.get_node_str() )
        for s in n1_leaf_strs:
            if False == n2_leaf_strs.__contains__(s):
                print "Mismatch at node with children: ", n1_leaf_strs
        
    